<?php

class Ext_Application_Resource_MetadataCache extends Zend_Application_Resource_ResourceAbstract
{
    protected $_frontend;
    protected $_backend;
    protected $_frontendOptions;
    protected $_backendOptions;

    public function init()
    {
        $options = $this->getOptions();

        $this->_frontend = "Core";
        if ( isset( $options['frontend'] ) ) {
            $this->_frontend = $options['frontend'];
        }
        $this->_backend= "Sqlite";
        if ( isset( $options['backend'] ) ) {
            $this->_backend = $options['backend'];
        }

        $this->_frontendOptions = array( "automatic_serialization" => true,
                                        "lifetime"=>3600);
        if ( isset( $options['backend_options'] ) ) {
            $this->_frontendOptions = array_merge($this->_frontendOptions , $options['backend_options'] );
        }

        $this->_backendOptions = array( "cache_db_complete_path" => "/tmp/metadata.sqlite.cache.db" );
        if ( isset( $options['backend_options'] ) ) {
            $this->_backendOptions = array_merge($this->_backendOptions , $options['backend_options'] );
        }

        $cache = Zend_Cache::factory(
            $this->_frontend, $this->_backend,
            $this->_frontendOptions, $this->_backendOptions);
        if ( isset( $options['clean'] ) && $options['clean'] ) {
            $cache->clean( Zend_Cache::CLEANING_MODE_ALL );
        }
        // Next, set the cache to be used with all table objects
        Zend_Db_Table_Abstract::setDefaultMetadataCache( $cache );
        return $this;
    }

    public function getFrontend() {
        return $this->_frontend;
    }

    public function getBackend() {
        return $this->_backend;
    }

    public function getFrontendOptions() {
        return $this->_frontendOptions;
    }

    public function getBackendOptions() {
        return $this->_backendOptions;
    }


}

